package com.example.robertluozizhao.baseframedemo.function.registerOrLogin.login.presenter;

import android.os.Handler;

import com.example.robertluozizhao.baseframedemo.function.registerOrLogin.login.LoginConstract.LoginConstract;
import com.example.robertluozizhao.baseframedemo.function.registerOrLogin.login.LoginConstract.OnHttpCallBack;
import com.example.robertluozizhao.baseframedemo.function.registerOrLogin.login.bean.User;
import com.example.robertluozizhao.baseframedemo.function.registerOrLogin.login.model.UserLoginModel;
import com.example.robertluozizhao.baseframedemo.function.registerOrLogin.login.view.UserLoginActivity;


/**
 * Created by robert.luozizhao on 2017/9/5 0005.
 */

public class UserLoginPresenter implements LoginConstract.LoginPersenter, OnHttpCallBack<User> {


    private final UserLoginActivity mUserLonginActivity;
    private final UserLoginModel mUserLoginModel;
    private Handler mHandler = new Handler();


    public UserLoginPresenter(UserLoginActivity userLoginActivity) {

        mUserLonginActivity = userLoginActivity;
        mUserLoginModel = new UserLoginModel();

    }

    @Override
    public void getListData() {
        String username = mUserLonginActivity.getUsername();
        String password = mUserLonginActivity.getPassword();
        mUserLoginModel.getListData(username,password,this);
    }


    @Override
    public void onSuccess(final User data) {

        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mUserLonginActivity.loginSuccess(data);
            }
        });


    }

    @Override
    public void onFailed(final String error) {

        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mUserLonginActivity.loginFailed(error);
            }
        });

    }
}
